package com.aerospace.serviceprovider.tcp;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpThreadServer {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8886);
        int i = 4;
        while(i>2){
            Socket accept = serverSocket.accept();
        }
    }

    public class ServerThread implements Runnable{
        private Socket accept;
        public ServerThread(Socket s){
            this.accept = s;
        }

        @Override
        public void run() {
            InputStream in;
            try {
                in = accept.getInputStream();
                byte b[] = new byte[1024];
                int len = in.read(b);
                System.out.println("接受到客户端数据，返回数据" + new String(b,0,len));
                OutputStream out = accept.getOutputStream();
                out.write("服务端已经接受".getBytes());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
